package com.euond.accv.gateway.utils;

import com.alibaba.fastjson.JSON;
import com.euond.common.vo.ResultVO;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @author: QiangLiu
 * @create: 2017-10-25 上午10:47
 * @version: 1.0
 **/
public class Utils {



    public static boolean isExistURLPath(String source,String target){
        if(StringUtils.isEmpty(source) || StringUtils.isEmpty(target))
            return true;

        if(source.indexOf(target) == -1){
            return false;
        }

        return true;
    }


    public static boolean isExistURLPath(List<String> sources,String target){
        if(sources == null || sources.size() == 0 || StringUtils.isEmpty(target))
            return true;

        for(String source : sources){
            if(source.indexOf(target) == -1){
                return false;
            }
        }
        return true;
    }


    public static Map<String,Object> resultMap(String retCode, String retMsg){
        Map<String,Object> resultMap = new HashedMap();
        ResultVO resultVO = new ResultVO();
        resultVO.setRetCode(retCode);
        if(StringUtils.isNotBlank(retMsg)){
            resultVO.setRetMsg(retMsg);
        }
        resultMap.put("flag",resultVO);

        return resultMap;
    }

    public static String resultJson(String retCode, String retMsg){
        Map<String,Object> resultMap = resultMap(retCode,retMsg);
        String jsonStr = JSON.toJSONString(resultMap);
        return jsonStr;
    }


//    public static void main(String[] args) {
//        String source = "/public/static/accv-dc/getInfo";
//        String target = "/accv-dc/getInfo";
//        boolean bl = isExistURLPath(source,target);
//        System.out.println(bl);
//    }
}
